<template>
	<!-- 店主管理 -->
	<view class="ownerManagement-main">
		<!-- 管理卡片 -->
		<view class="management-card">
			<view class="management-card-content">
				<view class="card-header">
					<view class="card-header-name">门店店主</view>
					<view class="card-header-num">
						<text class="num">
							{{ storeManagerInfo.coutn || '0' }}
						</text>
						位
					</view>
				</view>
				<view class="card-midden">
					<view class="card-item">
						<text>直字店主：</text>
						{{ storeManagerInfo.level1 || '0' }}位
					</view>
					<view class="card-item">
						<text>间享店主：</text>
						{{ storeManagerInfo.level2 || '0' }}位
					</view>
				</view>
				<view class="card-footer">
					<view class="cardNumItem">
						<view class="cardNumItem-name">订单总数</view>
						<view class="cardNumItem-num">
							{{ storeManagerInfo.order_count || '0' }}
						</view>
					</view>
					<view class="cardNumItem">
						<view class="cardNumItem-name">订单消费总额</view>
						<view class="cardNumItem-num">
							￥{{ storeManagerInfo.order_money || '0.00' }}
						</view>
					</view>
					<view class="cardNumItem">
						<view class="cardNumItem-name">订单结算总额</view>
						<view class="cardNumItem-num">
							￥{{ storeManagerInfo.closing_order_money == '0' ? '0.00' : storeManagerInfo.closing_order_money }}
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 筛选 -->
		<view class="incomeDetail-filter">
			<uni-segmented-control :current="current" :values="items" style-type="text" @clickItem="onClickItem" />
		</view>

		<view class="incomeDetail-info" v-if="incomeDetailInfo.length > 0">
			<view class="incomeDetail-info-item" v-for="item in incomeDetailInfo" :key="item.id">
				<view class="incomeDetail-info-item-top" v-if="current == 0 || current == 1">
					<view class="incomeDetail-image">
						<image :src="imageUrls(item.avatar)" style="width: 50px; height: 50px; border-radius: 50%; background-color: #f3f3f3"></image>
					</view>
					<view class="infos">
						<view class="nickname">
							{{ item.nickname || '暂无昵称' }}
						</view>
						<view class="mobile">手机：{{ item.mobile || '暂无电话' }}</view>
					</view>
					<view class="createtime">
						{{ formatTimestamps(item.createtime) }}
					</view>
				</view>
				<view class="incomeDetail-info-item-bottom" v-if="current == 0 || current == 2" :class="[current == 2 ? '' : 'active']">
					<view class="incomeDetail-info-item-top" v-for="jitem in item.invitees" :key="item.id">
						<view class="incomeDetail-image">
							<image :src="imageUrls(jitem.avatar)" style="width: 50px; height: 50px; border-radius: 50%; background-color: #f3f3f3"></image>
						</view>
						<view class="infos">
							<view class="nickname">
								{{ jitem.nickname || '暂无昵称' }}
							</view>
							<view class="mobile">手机：{{ jitem.mobile || '暂无电话' }}</view>
						</view>
						<view class="createtime">
							{{ formatTimestamps(jitem.createtime) }}
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 店主数据 -->
		<view class="ownerList" v-else>
			<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" text="暂无店主数据"></u-empty>
		</view>
	</view>
</template>

<script>
import { storeManager } from '../../../api/cloudManage/index.js';
import { formatTimestamp, imageUrl } from '../../../utils/tools.js';
export default {
	data() {
		return {
			current: 0,
			items: ['全部店主', '直享店主', '间享店主'],
			searchValue: '',
			storeType: '',
			storeManagerInfo: '',
			incomeDetailInfo: []
		};
	},
	onLoad() {
		this.current = 0;
		this.storeType = this.$store.state.storeType;
		this.getstoreManager();
	},
	methods: {
		async getstoreManager() {
			try {
				const resData = await storeManager({
					type: this.storeType
				});
				this.storeManagerInfo = resData.data;
				this.incomeDetailInfo = this.storeManagerInfo.list;
			} catch (e) {
				throw Error(e);
				//TODO handle the exception
			}
		},

		onClickItem(val) {
			const { currentIndex } = val;
			this.current = currentIndex;
		},

		formatTimestamps(val) {
			return formatTimestamp(val);
		},

		imageUrls(val) {
			return imageUrl(val);
		}
	}
};
</script>

<style>
page {
	background-color: #fff;
}
</style>

<style scoped lang="scss">
.ownerManagement-main {
	.management-card {
		box-sizing: border-box;
		padding: 20rpx;
		.management-card-content {
			background-color: #2979ff;
			border-radius: 24rpx;
			color: #fff;
			.card-header {
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 30rpx;
				font-weight: bold;
				box-sizing: border-box;
				padding: 40rpx 30rpx;
				.card-header-num {
					.num {
						font-size: 36rpx;
						font-weight: bold;
						margin-right: 8rpx;
					}
				}
			}
			.card-midden {
				font-size: 28rpx;
				border-bottom: 1px #f3f3f3 solid;
				box-sizing: border-box;
				padding: 30rpx;
				padding-top: 0px;
				.card-item {
					height: 60rpx;
					line-height: 60rpx;
				}
			}

			.card-footer {
				display: flex;
				align-items: center;
				justify-content: space-between;
				box-sizing: border-box;
				padding: 30rpx;
				font-size: 28rpx;
				.cardNumItem {
					.cardNumItem-name {
						margin-bottom: 8rpx;
					}
				}
			}
		}
	}

	.searchPage-input {
		display: flex;
		align-items: center;
		height: 80rpx;
		.searchPage-title {
			margin-right: 20rpx;
			color: #444;
		}
	}

	.ownerList {
		background-color: #f3f3f3;
		box-sizing: border-box;
		padding: 30rpx;
		height: calc(100vh - 400px);
	}
}

.incomeDetail-info {
	box-sizing: border-box;
	padding: 20rpx;
	.incomeDetail-info-item {
		.incomeDetail-info-item-bottom {
			font-size: 12px;
			box-sizing: border-box;
			border-bottom: 1px #f3f3f3 solid;
		}
		.incomeDetail-info-item-top {
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 12px;
			height: 70px;
			border-bottom: 1px #f3f3f3 solid;
		}

		.active {
			padding-left: 20px;
		}
	}
}

.incomeDetail-image {
	width: 55px;
}
.infos {
	flex: 1;
	height: 70px;
	display: flex;
	flex-direction: column;
	justify-content: center;
	.nickname {
		margin-bottom: 5px;
	}
}
.createtime {
	width: 134px;
	color: #999;
}
</style>